﻿@using ECGadmin.WebUI.CustomHelpers
@using ECGadmin.WebUI.Models
@model IEnumerable<ECGadmin.Common.PageDto>
@{
    ViewBag.Title = "PageList";
    Layout = "~/Views/Shared/_layout.cshtml";
}
<div class="toolBox">
    @Html.ToolBox(new List<object> { new Add { ClassCss = "Add", ActionName = "/Banner/AddPage" } })
</div>
<div style="overflow:hidden;">
    <table class="table-odd table-plist">
        <colgroup>
            <col style="width: 60px" />
            <col style="width: 500px" />
            <col />
            <col />
            <col style="width: 60px;" />
        </colgroup>
        <tr>
            <th scope="col">Thứ tự</th>
            <th scope="col">Tên trang</th>
            <th scope="col">Key</th>
            <th scope="col">Ngày tạo</th>
            <th scope="col"></th>
        </tr>
        @foreach (var item in Model)
        {
        <tr class="@string.Format("page-{0}", item.PageId)">
            <td>@item.Order</td>
            <td>
                @item.Name
            </td>
            <td>
                @item.PageKey
            </td>
            <td>
                @item.CreateDate.ToString("dd/MM/yy")
            </td>
            <td>
                <a href="@Url.Action("EditPage", "Banner", new { id = item.PageId })" title="chỉnh sửa" class="icon-edit-v2 fl-l bootstrapTangoSmall"></a>
                @Ajax.ActionLink("Xóa", "DeletePage", "Banner", new { id = item.PageId }, new AjaxOptions
                                                                      {
                                                                          Confirm = "Bạn chắc chắn muốn xóa page này!",
                                                                          OnSuccess = "AjaxReturnDataDeletePage"
                                                                      }, new { @class = "icon-delete fl-l bootstrapTangoSmall", title = "chỉnh sửa" })
            </td>
        </tr>
        }
    </table>
</div>
@section scripts
{
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script type="text/javascript">

        // AJAX ------- Xóa page
        function AjaxReturnDataDeletePage(returnData) {
            if (returnData.result <= 0) {
                alert('Trang này đã có Banner hoặc Vị trí!');
            }
            else {
                alert('Xóa thành công');
                $('.page-' + returnData.id).remove();
            }
        }
    </script>
}
